package cn.example.practice.model;

public class CartItem {
    private Long id;
    private Long goodsId;
    private String name;
    private float price;
    private int quantity;
    private String imageData;  // Base64 encoded image data
    private String imageType;  // Image MIME type

    public CartItem() {
    }

    public CartItem(Long id, Long goodsId, String name, float price, int quantity) {
        this.id = id;
        this.goodsId = goodsId;
        this.name = name;
        this.price = price;
        this.quantity = quantity;
    }

    public CartItem(Long id, Long goodsId, String name, float price, int quantity, String imageData, String imageType) {
        this.id = id;
        this.goodsId = goodsId;
        this.name = name;
        this.price = price;
        this.quantity = quantity;
        this.imageData = imageData;
        this.imageType = imageType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Long goodsId) {
        this.goodsId = goodsId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public float getTotal() {
        return price * quantity;
    }

    public String getImageData() {
        return imageData;
    }

    public void setImageData(String imageData) {
        this.imageData = imageData;
    }

    public String getImageType() {
        return imageType;
    }

    public void setImageType(String imageType) {
        this.imageType = imageType;
    }

    public String getImageUrl() {
        if (imageData != null && imageType != null) {
            return "data:" + imageType + ";base64," + imageData;
        }
        return null;
    }
}
